// ignore_for_file: file_names, slash_for_doc_comments, must_call_super, unnecessary_overrides, override_on_non_overriding_member, must_be_immutable, prefer_const_constructors

import 'package:flutter/material.dart';
import 'package:initproject/config/ConfigContext.dart';
import 'package:initproject/const/ImgConst.dart';
import 'package:initproject/demos/led/LEDPage.dart';
import 'package:initproject/demos/MultiLanguagePage.dart';
import 'package:mybaseplus/base/abstract/IFFR.dart';
import 'package:mybaseplus/base/abstract/IFFRefresh.dart';
import 'package:mybaseplus/base/abstract/IFFScaffold.dart';
import 'package:mybaseplus/base/tool/arouter/FFGoto.dart';
import 'package:mybaseplus/base/widget/layout/FFNavi2.dart';
import 'package:mybaseplus/base/widget/layout/FFTextButton.dart';
import 'package:mybaseplus/base/widget/page/FFListScaffold.dart';

class TestMain extends FFListScaffold {
  String? name;

  TestMain({
    Key? key,
    this.name,
  }) : super(key: key);

  @override
  TestMainState createState() => TestMainState();
}

class TestMainState extends FFListScaffoldState {
  /**固定写法 */
  @override
  IFFScaffold get iffScaffold => this;

  @override
  TestMain get widget => super.widget as TestMain;

  ///刷新控制
  @override
  IFFRefresh? get iffRefresh => refresh;
  late TestMainStateRefresh refresh = TestMainStateRefresh(state: this);

  @override
  FFPageSpacingParam? get ffPageSpacingParam => FFPageSpacingParam(bottomSpacing: true);

  /**固定写法end */

  @override
  void ffInitState() {
    super.ffInitState();
  }

  @override
  Widget? ffNavi(BuildContext context) {
    return FFNavi2.createNavi(
      context,
      title: "Title",
      titleCenter: true,
      actions: [
        FFNavi2Action(
          type: FFNavi2ActionType.img,
          value: ImgConst.imgred1,
          onClick: () {},
        ),
      ],
    );
  }

  @override
  Widget ffItem(BuildContext context, int index) {
    TestMainEntity entity = datas[index];
    return FFTextButton(
      padding: EdgeInsets.symmetric(horizontal: 16, vertical: 20),
      color: Colors.white,
      text: entity.title,
      fontColor: Colors.red,
      onClick: entity.onClick,
    );
  }
}

class TestMainStateRefresh with MFFRefresh {
  TestMainState state;

  TestMainStateRefresh({required this.state});

  @override
  bool? ffCanRefreshHead() {
    return true;
  }

  @override
  bool? ffCanRefreshFoot() {
    return true;
  }

  @override
  ffRefresh(bool isHead) {
    ffRefreshResult(isHead, test, state);
  }

  Future<IFFR> test(IRefreshParam? iRefreshParam) async {
    return R(rStatus: RStatus.result, data: [
      TestMainEntity(
          title: '多语言',
          onClick: () {
            FFGoto.gotoPage(getContext(), MultiLanguagePage());
          }),
      TestMainEntity(
          title: '自定义LED',
          onClick: () {
            FFGoto.gotoPage(getContext(), LEDPage());
          })
    ]);
  }
}

class TestMainEntity {
  String title;
  Function() onClick;

  TestMainEntity({
    required this.title,
    required this.onClick,
  });
}
